package com.example.learn.hwod;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class _24猜字谜 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //谜面
        List<Word> mm = Arrays.stream(sc.nextLine().split(","))
                .map(x -> new Word(x, convert(x))).collect(Collectors.toList());
        //谜底列表
        List<Word> md = Arrays.stream(sc.nextLine().split(","))
                .map(x -> new Word(x, convert(x))).collect(Collectors.toList());
        StringJoiner joiner = new StringJoiner(",");
        for (Word m : mm) {
            String mdStr = "not found";
            for (Word d : md) {
                if (m.getSortStr().equals(d.getSortStr())) {
                    if (!"not found".equals(mdStr)) {
                        mdStr+=","+d.getWord();
                    }else {
                        mdStr = d.getWord();
                    }
                }
            }

            joiner.add(mdStr);

        }
        System.out.println(joiner.toString());
    }

    public static String convert(String word) {
        String collect = Arrays.stream(word.split("")).distinct().sorted().collect(Collectors.joining());
        return collect;
    }

    static class Word {
        String word;
        String sortStr;

        public Word(String word, String sortStr) {
            this.word = word;
            this.sortStr = sortStr;
        }

        public String getWord() {
            return word;
        }

        public void setWord(String word) {
            this.word = word;
        }

        public String getSortStr() {
            return sortStr;
        }

        public void setSortStr(String sortStr) {
            this.sortStr = sortStr;
        }
    }
}
